package com.qu.tabhost.tabs.widget;

import android.content.Context;
import android.os.Build;
import android.support.annotation.DrawableRes;
import android.support.annotation.RequiresApi;
import android.support.annotation.StringRes;
import android.support.v4.app.Fragment;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.qu.tabhost.R;


/**
 * Created by quguangle on 2017/5/17.
 */

public class NavigationButton extends FrameLayout{
    private Fragment mFragment;
    private Class<?> mClx;
    private ImageView mImageView;
    private TextView mTextView;
    private TextView tv_dot;
    private String mTag;
    public NavigationButton(Context context) {
        super(context);
        init();
    }

    public NavigationButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public NavigationButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public NavigationButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }
    //加载布局
    public void init(){
        LayoutInflater inflater = LayoutInflater.from(getContext());
        View view = inflater.inflate(R.layout.nav_item_layout,this,true);
        mImageView = (ImageView) view.findViewById(R.id.nav_iv_icon);
        mTextView = (TextView) view.findViewById(R.id.nav_tv_title);
        tv_dot = (TextView) view.findViewById(R.id.nav_tv_dot);
    }
    //设置选中的操作
    public void setSelected(boolean isSelected){
        super.setSelected(isSelected);
        mImageView.setSelected(isSelected);
        mTextView.setSelected(isSelected);
    }
    //设置消息提示
    public void setTVdot(int count){
        if(count > 0){
            tv_dot.setVisibility(VISIBLE);
            tv_dot.setText(String.valueOf(count));
        }else{
            tv_dot.setVisibility(GONE);
        }
    }
    //对NavigationButton进行初始化
    public void init(@DrawableRes int drawaleRes, @StringRes int StrRes,Class<?> mCla){
        mImageView.setImageResource(drawaleRes);
        mTextView.setText(StrRes);
        mClx = mCla;
        mTag = mClx.getName();
    }
    public void setFragment(Fragment fragment){
        this.mFragment = fragment;
    }
    public Fragment getFragment(){
        return mFragment;
    }
    public String getTag(){
        return mTag;
    }
    public Class<?> getClx(){
        return mClx;
    }
}
